using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class TimedKillEvent : KillEvent, ITimedEvent
{
	public bool neededHeadshot;

	public int neededKills;

	public float neededTime;

	public bool disableIfAchieved = true;

	public bool achieved;

	public bool IfEvent(KillInfo newKill, List<KillInfo> KillsIList)
	{
		if (!achieved && weaponType == newKill.weaponType)
		{
			int num = 1;
			if (!neededHeadshot)
			{
				foreach (KillInfo KillsI in KillsIList)
				{
					if (weaponType == KillsI.weaponType && newKill.time - KillsI.time <= neededTime)
					{
						num++;
						if (num == neededKills)
						{
							return true;
						}
					}
				}
			}
			else if (newKill.headshot)
			{
				foreach (KillInfo KillsI2 in KillsIList)
				{
					if (weaponType == KillsI2.weaponType && KillsI2.headshot && newKill.time - KillsI2.time <= neededTime)
					{
						num++;
						if (num == neededKills)
						{
							return true;
						}
					}
				}
			}
		}
		return false;
	}

	public IEnumerator DisableForTime()
	{
		AddToAchidedList();
		if (disableIfAchieved)
		{
			achieved = true;
		}
		yield return new WaitForSeconds(neededTime);
		Reset();
	}

	public void AddToAchidedList()
	{
		GameplayEventsManager.instance.allTimedEvents.Add(this);
	}

	public void Reset()
	{
		achieved = false;
	}
}
